import util from "./util";

function wifi(params) {
  let _color = "#BBBFC0";
  if (params.row.State == "Online" || params.row.State == "Connected") {
    _color = "#53E0AB";
  }
  return {
    props: {
      type: "ios-wifi",
      color: _color,
      size: 20
    },
  };
}


let columns3 = [{
      title: "编号",
      key: "Tag",
      align: "center",
      sortable: "custom",
      width: 90,
      render: (h, params) => {
        if (params.row.$isEdit) {
          return h("input", {
            domProps: {
              value: params.row.Tag,
            },
            on: {
              click: (e) => {
                e.stopPropagation();
              },
              input: (e) => {
                e.stopPropagation();
                params.row._Tag = e.target.value;
              },
            },
          });
        } else {
          return h("span", params.row.Tag);
        }
      },
    },
    {
      title: "状态",
      align: "center",
      key: "State",
      minWidth: 90,
      sortable: "custom",
      render: (h, params) => {
        return h("Icon", wifi(params));
      },
    },
    {
      title: "电量",
      key: "BatteryLevel",
      align: "center",
      sortable: "custom",
      minWidth: 90,
      render: (h, params) => {
        // let {
        //   batteryIcon,
        //   batteryString,
        //   batteryContainer,
        //   spanStyle,
        // } = battery(params);
        // return h("div", batteryContainer, [
        //   h("Icon", batteryIcon),
        //   h("span", spanStyle, batteryString),
        // ]);
        return h("batteryCustom", {
          props: {
            batteryLevel: params.row.BatteryLevel,
            State: params.row.State,
          },
        });
      },
    },
    {
      title: "类型",
      key: "Type",
      align: "center",
      minWidth: 90,
      sortable: "custom",
      render: (h, params) => {
        if (params.row.$isEdit) {
          return h(
            "select", {
              on: {
                click: (e) => {
                  e.stopPropagation();
                },
                change: (e) => {
                  params.row._Type = e.target.value;
                },
              },
            },
            [
              h(
                "option", {
                  props: {
                    value: "请选择",
                  },
                },
                "请选择"
              ),
              h(
                "option", {
                  props: {
                    value: "Pistol",
                  },
                },
                "Pistol"
              ),
              h(
                "option", {
                  props: {
                    value: "Grenade",
                  },
                },
                "Grenade"
              ),
            ]
          );
        } else {
          return h("span", params.row.Type);
        }
      },
    },
    {
      title: "绑定",
      align: "center",
      minWidth: 90,
      render: (h, params) => {
        return h("span", params.row.Bindings ? "绑定" : "未绑定");
      },
    },
    {
      title: "训练组",
      align: "center",
      minWidth: 90,
      render: (h, params) => {
        if (params.row.Bindings) {
          let bindInfo = params.row.Bindings.find(
            (item) => item.Type == "Site"
          );
          return h("span", bindInfo ? bindInfo.Display : "---");
        } else {
          return h("span", "---");
        }
      },
    },
    {
      title: "绑定头显",
      align: "center",
      minWidth: 90,
      render: (h, params) => {
        if (params.row.Bindings) {
          let bindInfo = params.row.Bindings.find(
            (item) => item.Type == "Device"
          );
          return h("span", bindInfo ? bindInfo.Display : "---");
        } else {
          return h("span", "---");
        }
      },
    },
  ],
  columns2 = [{
      title: "编号",
      key: "Tag",
      align: "center",
      sortable: "custom",
      width: 90,
      render: (h, params) => {
        if (params.row.$isEdit) {
          return h("input", {
            domProps: {
              value: params.row.Tag,
            },
            on: {
              click: (e) => {
                e.stopPropagation();
              },
              input: (e) => {
                e.stopPropagation();
                params.row._Tag = e.target.value;
              },
            },
          });
        } else {
          return h("span", params.row.Tag);
        }
      },
    },
    {
      title: "SN",
      key: "SN",
      align: "center",
      sortable: "custom",
      minWidth: 90,
    },
    {
      title: "状态",
      align: "center",
      key: "State",
      sortable: "custom",
      minWidth: 90,
      render: (h, params) => {
        return h("Icon", wifi(params));
      },
    },
    {
      title: "电量",
      key: "BatteryLevel",
      align: "center",
      sortable: "custom",
      minWidth: 90,
      render: (h, params) => {
        // let {
        //   batteryIcon,
        //   batteryString,
        //   batteryContainer,
        //   spanStyle,
        // } = battery(params);
        // return h("div", batteryContainer, [
        //   h("Icon", batteryIcon),
        //   h("span", spanStyle, batteryString),
        // ]);
        return h("batteryCustom", {
          props: {
            batteryLevel: params.row.BatteryLevel,
            State: params.row.State,
          },
        });
      },
    },
    {
      title: "IP",
      key: "IP",
      align: "center",
      sortable: "custom",
      minWidth: 90,
    },
    {
      title: "训练点",
      key: "SiteID",
      align: "center",
      minWidth: 90,
      render: (h, params) => {
        if (params.row.Bindings) {
          let bindInfo = params.row.Bindings.find(
            (item) => item.Type == "Site"
          );
          return h("span", bindInfo ? bindInfo.Display : "---");
        } else {
          return h("span", "---");
        }
      },
    },
  ],
  columns1 = [{
      title: "编号",
      key: "ID",
      align: "center",
      sortable: "custom",
      width: 90,
    },
    {
      title: "名称",
      key: "Name",
      align: "center",
      sortable: "custom",
      minWidth: 90,
      render: (h, params) => {
        if (params.row.$isEdit) {
          return h("input", {
            domProps: {
              value: params.row.Name,
            },
            on: {
              click: (e) => {
                e.stopPropagation();
              },
              input: (e) => {
                e.stopPropagation();
                params.row._Name = e.target.value;
              },
            },
          });
        } else {
          return h("span", params.row.Name);
        }
      },
    },
    {
      title: "状态",
      align: "center",
      key: "State",
      sortable: "custom",
      minWidth: 90,
      render: (h, params) => {
        return h("Icon", wifi(params));
      },
    },
    {
      title: "头显",
      align: "center",
      key: "BindingOnlineCount",
      minWidth: 90,
      render: (h, params) => {
        return h(
          "span", {},
          `${params.row.BindingOnlineCount} / ${params.row.BindingNumber}`
        );
      },
    },
    {
      title: "登入登出时间",
      align: "center",
      key: "LoginTime",
      sortable: "custom",
      minWidth: 172,
      render: (h, params) => {
        let outTime = "---------------------";
        if (params.row.LogoutTime) {
          outTime = util.getTime(params.row.LogoutTime);
        }
        return h("div", [
          h("p", {}, [
            h("Icon", {
              style: {
                marginRight: "3px"
              },
              props: {
                type: "ios-log-in",
                size: 20
              },
            }),
            h("span", util.getTime(params.row.LoginTime)),
          ]),
          h("p", {}, [
            h("Icon", {
              style: {
                marginRight: "8px"
              },
              props: {
                type: "ios-log-out",
                size: 20
              },
            }),
            h("span", outTime),
          ]),
        ]);
      },
    },
  ];

let user_columns1 = [{
      title: "编号",
      key: "ID",
      align: "center",
      width: 90,
      sortable: "custom",
    },
    {
      title: " ",
      key: "Img",
      align: "center",
      minWidth: 90,
      render: (h, params) => {
        return h("img", {
          style: {
            verticalAlign: "middle"
          },
          attrs: {
            src: params.row.Portrait,
            height: 50,
            width: 50,
          }
        })
      },
    },
    {
      title: "名称",
      key: "Name",
      align: "center",
      minWidth: 90,
    },
    {
      title: "年龄",
      key: "Birthday",
      align: "center",
      minWidth: 90,
      sortable: "custom",
      render: (h, params) => {
        let age =
          new Date().getFullYear() -
          new Date(params.row.Birthday).getFullYear();
        return h("span", {}, age);
      },
    },
    {
      title: "身高",
      key: "Height",
      align: "center",
      minWidth: 90,
      sortable: "custom",
    },
    {
      title: "级别",
      key: "Title",
      align: "center",
      minWidth: 90,
    },
  ],
  user_columns2 = [{
      title: "编号",
      key: "ID",
      align: "center",
      width: 90,
      sortable: "custom",
    },
    {
      title: " ",
      key: "Img",
      align: "center",
      minWidth: 90,
      render: (h, params) => {
        return h("img", {
          style: {
            verticalAlign: "middle"
          },
          attrs: {
            src: params.row.Portrait,
            height: 50,
            width: 50,
          }
        })
      },
    },
    {
      title: "名称",
      key: "Name",
      align: "center",
      minWidth: 90,
    },
    {
      title: "年龄",
      key: "Age",
      align: "center",
      minWidth: 90,
      sortable: "custom",
      render: (h, params) => {
        let age =
          new Date().getFullYear() -
          new Date(params.row.Birthday).getFullYear();
        return h("span", {}, age);
      },
    },
    {
      title: "身高",
      key: "Height",
      align: "center",
      minWidth: 90,
      sortable: "custom",
    },
    {
      title: "级别",
      key: "Title",
      align: "center",
      minWidth: 90,
    },
  ],
  user_columns3 = [{
      title: "编号",
      key: "ID",
      align: "center",
      width: 90,
      sortable: "custom",
    },
    {
      title: "账号",
      key: "Name",
      align: "center",
      minWidth: 90,
      // render: (h, params) => {
      //   return h("span", {}, params.row.Account.Name);
      // },
    },
    {
      title: "名称",
      key: "Tick",
      align: "center",
      minWidth: 90,
    },
    {
      title: "邮箱",
      key: "Email",
      align: "center",
      minWidth: 100,
    },
  ];
let content_columns = [{
    title: "编号",
    key: "ID",
    align: "center",
    width: 90,
  },
  {
    title: "名称",
    key: "Name",
    align: "center",
    minWidth: 90,
    sortable: "custom",
  },
  {
    title: "版本",
    key: "VersionName",
    align: "center",
    minWidth: 90,
    render: (h, params) => {
      return h("sapn", {}, params.row.VersionName ? params.row.VersionName : "暂无")
    }
  },
  {
    title: "更新时间",
    key: "LastModified",
    align: "center",
    minWidth: 100,
    sortable: "custom",
    render: (h, params) => {
      let str = params.row.LastModified ? util.getTime(params.row.LastModified) : "暂无"
      return h("span", {}, str)
    }
  },
];
let record_columns = [{
    title: "编号",
    key: "ID",
    align: "center",
    width: 90,
  },
  {
    title: "课程名称",
    align: "center",
    minWidth: 90,
    render: (h, params) => {  
      return h("span", params.row.Lesson && params.row.Lesson.Name)
    }
  },
  // {
  //   title: "内容图片",
  //   key: "ImgTag",
  //   align: "center",
  //   minWidth: 90,
  // },
  {
    title: "训练时间",
    key: "EndTime",
    align: "center",
    minWidth: 90,
    render: (h, params) => {
      return h("span", util.getTime(params.row.EndTime))
    }
  },
  {
    title: "人员",
    key: "Peoples",
    align: "center",
    minWidth: 90,
    render: (h, params) => {
      let str = params.row.Peoples && params.row.Peoples.map(item => item.Name).join("/")
      return h("span", str)
    }
  },
  {
    title: "类型",
    key: "TrainType",
    align: "center",
    minWidth: 90,
  },
];
let sys_columns1 = [{
      title: "编号",
      key: "ID",
      align: "center",
      width: 90,
    },
    {
      title: "名称",
      key: "ID",
      align: "center",
      minWidth: 90,
    },
    {
      title: "状态",
      key: "ID",
      align: "center",
      minWidth: 90,
    },
    {
      title: "当前版本",
      key: "ID",
      align: "center",
      minWidth: 90,
    },
    {
      title: "最新版本",
      key: "ID",
      align: "center",
      minWidth: 90,
    },
  ],
  sys_columns2 = [{
      title: "编号",
      key: "ID",
      align: "center",
      width: 90,
    },
    {
      title: "SN",
      key: "ID",
      align: "center",
      minWidth: 90,
    },
    {
      title: "状态",
      key: "ID",
      align: "center",
      minWidth: 90,
    },
    {
      title: "当前版本",
      key: "ID",
      align: "center",
      minWidth: 90,
    },
    {
      title: "最新版本",
      key: "ID",
      align: "center",
      minWidth: 90,
    },
  ],
  sys_columns3 = [{
      title: "编号",
      key: "ID",
      align: "center",
      width: 90,
    },
    {
      title: "名称",
      key: "Name",
      align: "center",
      minWidth: 90,
    },
    {
      title: "状态",
      key: "State",
      align: "center",
      minWidth: 90,
      render: (h, params) => {
        return h("Icon", wifi(params));
      },
    },
    {
      title: "当前版本",
      key: "CurVersion",
      align: "center",
      minWidth: 90,
    },
    {
      title: "最新版本",
      key: "LastVersion",
      align: "center",
      minWidth: 90,
    },
  ];

export default (type) => {
  switch (type) {
    case "Site":
      return columns1;
    case "Device":
      return columns2;
    case "Accessory":
      return columns3;
    case "Train":
      return user_columns1;
    case "Coach":
      return user_columns2;
    case "Admin":
      return user_columns3;
    case "Content":
      return content_columns;
    case "Record":
      return record_columns;
    case "Site_sys":
      return sys_columns1;
    case "Device_sys":
      return sys_columns2;
    case "Accessory_sys":
      return sys_columns3;
  }
};